package com.itheima.map;

import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;

/**
 * @author zhangbaiyan
 * @date 2024-09-12 16:49
 * @description:
 * @version:
 */
public class test5 {
    public static void main(String[] args) {
        //1.定义字符串
        String str = "aababcabcdabcde";
        //2.创建集合
        TreeMap<Character, Integer> tmpMap = new TreeMap<>();
        //3.遍历字符串得到里面的每一个字符
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            //4.判断集合中是否有该字符，如果没有，则添加，如果有，则更新
            if (tmpMap.containsKey(ch)) {
                int count = tmpMap.get(ch);
                tmpMap.put(ch, count + 1);
            } else {
                tmpMap.put(ch, 1);
            }
        }
        StringBuilder sb = new StringBuilder();
        tmpMap.forEach((character, integer)-> sb.append(character).append("(").append(integer).append(")"));
        System.out.println(sb);
    }


}

